package de.hska.reka.websockets.model;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.springframework.context.ApplicationContext;

public class ClassMethod {
	private ApplicationContext context;
	private String beanName;
	private Method method;
	
	public Object invoke(Object[] params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
		if(context.getBean(beanName)==null) {
			throw new IllegalAccessError("Bean not found");
		}
		return this.method.invoke(context.getBean(beanName), params);
	}

	public ApplicationContext getContext() {
		return context;
	}

	public void setContext(ApplicationContext context) {
		this.context = context;
	}

	public String getBeanName() {
		return beanName;
	}

	public void setBeanName(String beanName) {
		this.beanName = beanName;
	}

	public Method getMethod() {
		return method;
	}

	public void setMethod(Method method) {
		this.method = method;
	}

	
}
